import 'package:flutter/material.dart';
import 'package:flutter_vant/component/overlay.dart';
import 'package:flutter_vant/main.dart';
import 'package:simulator/components/DemoView/index.dart';

class OverlayView extends HookWidget {
  const OverlayView({Key? key}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    final isShow = useState(false);
    openOverLay(Map item) {
      isShow.value = true;
    }

    List<Widget> renderList(List<Map> data) {
      return data.map((e) {
        return DemoView(
            title: e['name'],
            children: (e['children'] as List).map((el) {
              return VanButton(
                text: el['name'],
                type: VanButtonType.primary,
                onClick: () => openOverLay(el),
              );
            }).toList());
      }).toList();
    }

    List<Widget> renderMain() {
      List<Map> data = [
        {
          "name": '基础用法',
          "children": [
            {"name": "显示遮罩层"}
          ]
        },
        {
          "name": "嵌入内容",
          "children": [
            {"name": '嵌入内容', 'content': TextView('内容')}
          ]
        }
      ];
      return renderList(data);
    }

    return HookView(title: 'Overlay', children: [
      ...renderMain(),
      VanOverlay(keyName: 'overlay', child: TextView('测试'))
    ]);
  }
}
